<template>
  <div class="table-box">
    <ProTable ref="proTable" :columns="columns" :request-api="getConfigList" :pagination="false">
      <!-- 表格操作 -->
      <template #operation="scope">
        <el-button v-auth="'config_save'" type="primary" link :icon="EditPen" @click="openDrawer('编辑', scope.row)">
          编辑
        </el-button>
      </template>
    </ProTable>
    <ConfigEdit ref="drawerRef" />
  </div>
</template>
<script setup lang="tsx" name="dictType">
import { ref, reactive } from "vue";
import { Support } from "@/api/interface";
import ProTable from "@/components/ProTable/index.vue";
import { ProTableInstance, ColumnProps } from "@/components/ProTable/interface";
import { getConfigList, saveConfig } from "@/api/modules/support";
import ConfigEdit from "@/views/support/config/ConfigEdit.vue";
// ProTable 实例
const proTable = ref<ProTableInstance>();

// 表格配置项
const columns = reactive<ColumnProps<Support.OperationLog>[]>([
  { prop: "configName", label: "配置项名称" },
  { prop: "configValue", label: "配置项值" },
  { prop: "configDesc", label: "配置项描述" },
  { prop: "operation", label: "操作", width: 250, fixed: "right" }
]);

// 打开 drawer(新增、查看、编辑)
const drawerRef = ref<InstanceType<typeof ConfigEdit> | null>(null);
const openDrawer = (title: string, row: Partial<Support.Config> = {}) => {
  const params = {
    title,
    isView: title === "查看",
    row: { ...row },
    api: saveConfig,
    getTableList: proTable.value?.getTableList
  };
  drawerRef.value?.acceptParams(params);
};
</script>
